/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cip.esymons.eventos.bc;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.cip.esymons.eventos.be.TipoConcepto;

/**
 *
 * @author Liszardo
 */
public class TipoConceptoDelegate {

    TipoConceptoFacadeLocal local;

    public TipoConceptoDelegate() {
        local = lookupTipoConceptoFacade();
    }

    public TipoConcepto buscarTipoConcepto(Integer tpcCodigo) {
        try {
            return local.find(tpcCodigo);
        } catch (Exception e) {
            return new TipoConcepto();
        }
    }

    private TipoConceptoFacadeLocal lookupTipoConceptoFacade() {
        try {
            Context c = new InitialContext();
            return (TipoConceptoFacadeLocal) c.lookup("java:comp/env/TipoConceptoFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public boolean guardar(TipoConcepto concepto) {
        try {
            local.create(concepto);
            return true;
        } catch (Exception ex) {
            return false;
        }
    }

    public boolean actualizar(TipoConcepto concepto) {
        try {
            local.edit(concepto);
            return true;
        } catch (Exception ex) {
            return false;
        }
    }

    public List<TipoConcepto> listarTipoConceptos() {
        try {
            return local.findAll();
        } catch (Exception e) {
            return new ArrayList<TipoConcepto>();
        }
    }




}
